package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserMapper;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsUserService;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/22 9:28
 */
@Service
public class DtsUserServiceImpl implements DtsUserService {
    @Autowired
    private DtsUserMapper dtsUserMapper;
    @Override
    public List<DayStatis> findDayStatis(Integer statisDayNum) {
        return dtsUserMapper.findDayStatis(statisDayNum);
    }

    @Override
    public long getcount() {
        QueryWrapper<DtsUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",false);
        return dtsUserMapper.selectCount(queryWrapper);
    }

    /**
     * 会员列表查询
     * @param nickname
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    @Override
    public IPage<DtsUser> findListByQuery(String nickname, Integer page, Integer limit, String sort, String order,String mobile) {
        return dtsUserMapper.selectPage(new Page(page,limit),
                new QueryWrapper<DtsUser>()
                        .like(StringUtils.hasText(nickname),"nickname",nickname)
                        .like(StringUtils.hasText(mobile), "mobile", mobile)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }
}
